package com.gjy.concurrency.h1;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-05-29 16:14:24
 */
public class ThreadInfo {

    private static final Logger logger = LoggerFactory.getLogger(ThreadInfo.class);

    @Test
    public void test4() {
        byte b = 0;
        System.out.println(new String(new byte[]{b}));
    }

    @Test
    public void test3() {
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();

        java.lang.management.ThreadInfo[] infos = bean.dumpAllThreads(false, false);

        for (java.lang.management.ThreadInfo info : infos) {

            System.out.println(info.getThreadName());
        }
    }

    @Test
    public void test1() {
        int count = Thread.activeCount();
        logger.info("thread count = {}", count);

    }

    @Test
    public void test2() {
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

        long[] ids = threadMXBean.getAllThreadIds();
        for (long id : ids) {
            logger.info("id = {}", id);
            java.lang.management.ThreadInfo threadInfo = threadMXBean.getThreadInfo(id);

            logger.info("threadInfo = {}", threadInfo);
        }
    }
}
